package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>course题库的controller<p>
 *
 * @author LSL
 * @date 2022/5/31 9:51
 */
@RestController
@RequestMapping("/courseController")
@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;

//    查询全部 有层级
    @GetMapping("/findAllCourse")
    public ResponseEntity findAllCourse() {
        ResponseEntity responseEntity = courseService.findAllCourse();
        return responseEntity;
    }

//    查询所有  没有层级
    @GetMapping("/course")
    public ResponseEntity findAll(){
        ResponseEntity responseEntity = courseService.findAll();
        return  responseEntity;
    }

//    批量删除
    @DeleteMapping("batchDelete")
    public ResponseEntity batchDelete(@RequestBody int[] courseIdArray){
        ResponseEntity responseEntity = courseService.batchDelete(courseIdArray);
        return responseEntity;
    }


//    单个删除
    @DeleteMapping("course/{id}")
    public ResponseEntity deleteOneById(@PathVariable int id){
        System.out.println(id+"===================");
        return courseService.deleteOneById(id);
    }


    @PostMapping("/findCourseByName")
    public ResponseEntity findCourseByName(Map<String, String> course) {
        //建立map集合

        return courseService.findCourseByName(course);
    }
    @RequestMapping("/findCourseByTopicId")
    public ResponseEntity findCourseByTopicId(int id) {
        return courseService.findCourseByTopicId(id);
    }
}
